
import 'package:bot_toast/bot_toast.dart';
import 'package:flutter/material.dart';
import 'package:shopping_group/base/base_constant.dart';
import 'package:shopping_group/http/apis/apis.dart';
import 'package:shopping_group/http/http_request_all.dart';
import 'package:shopping_group/main/lz_hot_cakes/model/lz_hot_cakes_play_video_model.dart';
import 'package:shopping_group/main/lz_hot_cakes/model/lz_hot_cakes_product_model.dart';

class LzHotCakesViewModel {
  //请求热销列表数据
  getHotCakes(BuildContext context, successCallBlock) {
    Map<String, dynamic> data = {};
    data['val'] = "CST_RE_XIAO_4_DS";
    data['userId'] = BaseConstant.userId;
    data['pageIndex'] = 1;
    data['pageSize'] = 100;

    HttpUtilAll.post(Apis.AUC_COMMO_URL, data: data, success: (result) {
      // 请求成功返回的数据

      if (data != null) {
        List<LzHotCakesProductModel> cakesModels = List.from(result).map((e) {
          return LzHotCakesProductModel.fromMap(e);
        }).toList();
        successCallBlock(cakesModels);
      } else {
        successCallBlock([]);
      }

      // eventBus.fire(CommoSpecEvent(_listEntity, _type));
    }, error: (errorMsg) {
      // 请求失败返回的错误信息
      BotToast.showText(text: errorMsg);
    });
  }

  //获取视频播放次数
  getUserLookGuanGaoCtInfo(BuildContext context, Function(Map<String, dynamic>) successCallBlock) {
    HttpUtilAll.post(Apis.GUAN_GAOCT_INFO, data: {"val": BaseConstant.userId ?? ""}, success: (result) {
      successCallBlock(Map.from(result));
    }, error: (errorMsg) {
      successCallBlock({});
      BotToast.closeAllLoading();
      // 请求失败返回的错误信息
      BotToast.showText(text: errorMsg);
    });
  }

  //初始化播放视频的参数
  initFuliVideoParma(Function(LzHotCakesPlayVideoModel) successCallBlock) {
    HttpUtilAll.post(Apis.SHOW_FULI_GROUP_APP, data: {"val": BaseConstant.userId}, success: (result) {
      LzHotCakesPlayVideoModel playModel = LzHotCakesPlayVideoModel.fromMap(result);
      successCallBlock(playModel);
    }, error: (errorMsg) {
      successCallBlock(null);
      BotToast.closeAllLoading();
      // 请求失败返回的错误信息
      BotToast.showText(text: errorMsg);
    });
  }

  //检查播放视频的来源
  checkoutPlayVideo(LzHotCakesPlayVideoModel playModel, Function(Map<String, dynamic>) successCallBlock) {
    BotToast.showLoading();

    Map<String, dynamic> data = {};
    data["userId"] = BaseConstant.userId;
    data['groupSpecId'] = playModel.groupSpecId;

    HttpUtilAll.post(Apis.FL_VALIDATE_URL, data: data, success: (result) {
      BotToast.closeAllLoading();
      successCallBlock(Map.from(result));
    }, error: (errorMsg) {
      successCallBlock({});

      BotToast.closeAllLoading();

      // 请求失败返回的错误信息
      BotToast.showText(text: errorMsg);
    });
  }
}
